# This is just to load properties file
# Version 1.0.0 - Sanjay
# Version 1.0.1 - Removed splitList

import java.util as util
import java.io as javaio
import javax.management as mgmt
import sys

lineSep = java.lang.System.getProperty('line.separator')

_modules = [
            'sys',
            'time',
            're',
            'glob',
            'os',
            'os.path',
            'getopt',
            'traceback',
           ]

for module in _modules:
  try:
    locals()[module] = __import__(module, {}, {}, [])
  except ImportError:
    print 'Error importing %s.' % module

#######################################
# Superfluous
#######################################
def wsadminToList(inStr):
        inStr = inStr.rstrip();
        outList=[]
        if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
                tmpList = inStr[1:-1].split(" ")
        else:
                tmpList = inStr.split("\n")  #splits for Windows or Linux
        for item in tmpList:
                item = item.rstrip();        #removes any Windows "\r"
                if (len(item)>0):
                        outList.append(item)
        return outList
#endDef

###################################################################################################################################################################################
###################################################################################################################################################################################


#######################################
#MAIN	
#######################################
props = util.Properties()
propfile_name=sys.argv[0]
print "File name ", propfile_name
inside = props.load(javaio.FileInputStream(propfile_name))

# get the values from property file
trace=props.getProperty("Trace")
applicationName=props.getProperty("applicationName")
cellName=props.getProperty("cellName")
clusterName=props.getProperty("clusterName")
nodeName=props.getProperty("nodeName")
hostName=props.getProperty("hostName")
serverName=props.getProperty("serverName")
numberOfServers=props.getProperty("numberOfServers")
jvmMin=props.getProperty("jvmMin")
jvmMax=props.getProperty("jvmMax")
genericArgs=props.getProperty("genericArgs")

sibBusName=props.getProperty("sibBusName")
schemaName=props.getProperty("schemaName")
virtualHost=props.getProperty("virtualHost")
virtualhostPort=props.getProperty("virtualhostPort")

jdbcProviderName=props.getProperty("jdbcProviderName")

datasourceName1=props.getProperty("dataSourceName.1")
dataSourceJndi1=props.getProperty("dataSourceJndi.1")
database1=props.getProperty("database.1")
server1=props.getProperty("server.1")
applicationName1=props.getProperty("applicationName.1")
user1=props.getProperty("user.1")
password1=props.getProperty("password.1")

datasourceName2=props.getProperty("dataSourceName.2")
dataSourceJndi2=props.getProperty("dataSourceJndi.2")
database2=props.getProperty("database.2")
server2=props.getProperty("server.2")
applicationName2=props.getProperty("applicationName.2")
user2=props.getProperty("user.2")
password2=props.getProperty("password.2")

datasourceName3=props.getProperty("dataSourceName.3")
dataSourceJndi3=props.getProperty("dataSourceJndi.3")
database3=props.getProperty("database.3")
server3=props.getProperty("server.3")
applicationName3=props.getProperty("applicationName.3")
user3=props.getProperty("user.3")
password3=props.getProperty("password.3")

datasourceName4=props.getProperty("dataSourceName.4")
dataSourceJndi4=props.getProperty("dataSourceJndi.4")
database4=props.getProperty("database.4")
server4=props.getProperty("server.4")
applicationName4=props.getProperty("applicationName.4")
user4=props.getProperty("user.4")
password4=props.getProperty("password.4")

datasourceDescription=props.getProperty("dataSourceDescription")
datasourceJNDI=props.getProperty("dataSourceJndi")
driverpath=props.getProperty("driverpath")
datasourceHelperClass=props.getProperty("implementationClassName")

if (trace == "ON"):
	print " Application Name is " +applicationName
	print " Cell is " +cellName
	print " Cluster is " +clusterName
	print " Sib Name is " +sibBusName
	print " Node Name is " +nodeName
	print " Server Name is " +serverName
	print " jvm Min is " +jvmMin
	print " jvm Max is " +jvmMax
	print " generic Args are " +genericArgs
	print " Virtual Host is " +virtualHost
	print " JdbC Provider Name is " +jdbcProviderName
	print " DataSource Name1 is " +datasourceName1
	print " DataSource Name2 is " +datasourceName2
	print " DataSource Name3 is " +datasourceName3
	print " DataSource Name4 is " +datasourceName4
#endDef



print "3. Create Data Source"
createDataSource1 (jdbcProviderName,cellName,clusterName,datasourceName4,dataSourceJndi4,database4,server4)
print "<< Data Source created. "

print "3. modifyDS"
#integratedSecurity="false"
#modifyDS3(cellName,clusterName,jdbcProviderName,datasourceName1,database1, server1,"applicationName","java.lang.String",applicationName1,"user","java.lang.String",user1,"password","java.lang.String",password1, applicationName,integratedSecurity)
print "<< Modified DS"

AdminConfig.save()
print " ---> Staging Configuration Saved"




